package com.example.waterfall.adapter;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.example.waterfall.R;
import com.example.waterfall.model.CommentInfo;
import com.example.waterfall.model.Images;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 评论列表
 * 
 * @author huangrongcai
 * 
 */
public class CommentLIstAdapter extends BaseAdapter {

	private ViewHolder holder;
	private LinkedList<CommentInfo> mInfos;
	
	public CommentLIstAdapter() {
		mInfos = new LinkedList<CommentInfo>();
		}

	/**
	 * 添加一个数据到例前
	 * 
	 * @param datas
	 */
	public void addItemTop(CommentInfo data) {
		mInfos.addFirst(data);
		notifyDataSetChanged();
	}
	/**
	 * 添加一个数据
	 * 
	 * @param datas
	 */
	public void addItem(CommentInfo datas) {
		mInfos.add(datas);
		notifyDataSetChanged();
	}

	/**
	 * 加入数据
	 * 
	 * @param datas
	 */
	public void addItemLast(List<CommentInfo> datas) {
		mInfos.addAll(datas);
	}

	/**
	 * 加在在队列前
	 * 
	 * @param datas
	 */
	public void addItemsTop(List<CommentInfo> datas) {
		for (CommentInfo info : datas) {
			mInfos.addFirst(info);
		}
	}

	@Override
	public int getCount() {
		return mInfos.size();
	}

	@Override
	public Object getItem(int position) {
		return mInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CommentInfo info  = mInfos.get(position);
		
		if (convertView == null) {
			LayoutInflater layoutInflator = LayoutInflater.from(parent
					.getContext());
			convertView = layoutInflator.inflate(
					R.layout.layout_sns_piccm_detail, null);
			holder = new ViewHolder();
			holder.commentText = (TextView) convertView
					.findViewById(R.id.tv_listcomment);
			convertView.setTag(holder);
		}
		holder = (ViewHolder) convertView.getTag();
		holder.commentText.setText("评论" + position+info.textStr);

		return convertView;
	}

	class ViewHolder {
		public TextView commentText;

	}

	/**
	 * 模拟数据
	 * 
	 * @return
	 */
	private List<CommentInfo> getCommentInfo() {
		List<CommentInfo> list = new ArrayList<CommentInfo>();
		for (int i = 0; i < Images.imageUrls.length; i++) {
			CommentInfo info = new CommentInfo();
			info.textStr = "评论" + i;
			list.add(info);
		}
		return list;
	}
}
